import Parser from './Parser'
export default class AttrParser extends Parser {
    parse () {
        let t1 =  this.view.match(/\s+\w+[^=\'\"]*=[^\'\"]*[\"\']{1}[^\'\"]*\{\{[^\{]+\}\}[^\'\"]*[\"\']{1}/g);
        if(!t1) return new Function('return;');
        let $out = '\n';
        for(let t0 of t1){
            let l = t0.replace(/\s+/g,'').split('=');
            let [attr,val] = l;
            let parser = new Parser(val)
            parser.setResolver(this.resolver)
            let fn = parser.parse();
            let fnCode = fn.toString().replace('anonymous','_'+ attr.replace(/\-/g,'_'));
            $out += fnCode + '\nele.setAttribute(\'' + attr + '\',_' + attr.replace(/\-/g,'_') + '.apply(this).replace(/[\\"\\\']/g,\'\'));\n';
        }
        return new Function('ele', this.fn + $out);
    }
}